const defaultAvatarUrl = 'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/avatarUrl.png'
const app =getApp()
Page({
  data: {
    path:'',
    isWxLogin:true,
    avatarUrl: defaultAvatarUrl,
    theme: wx.getSystemInfoSync().theme,
    value:'',
    isUpdate:false,
    parmas:'?ready=1',
    needSetting:app.globalData.needAuthorization
  },
  onLoad: function (options) {
    let that = this
    that.setData({
      path:options.path?options.path:''
    })
    for(var i in options){
      if(i !='path'){
        that.setData({
          parmas:that.data.parmas + '&'+ i+'='+options[i]
        })
      }
    }
  },
  xChildReload: function () {
    var pages = getCurrentPages(); //当前页面栈
    if ( pages.length > 1) {
      var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
      if(beforePage.xInfo()){
        beforePage.xInfo(); //触发父页面中的方法
        
      }
    }
  },
  handleTouchInput:function(){
    this.setData({
      innerShow:true
    })
  },
  changePrivacySetting:function(e){
    this.setData({
      needSetting:false
    })
  },
  xPhone: async function (e) {
    let that = this;
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
      wx.showModal({
        title: '警告',
        content: '如不提供有效手机号我们将无法向您提供有效服务。',
        cancelColor: 'cancelColor',
        showCancel:false
      })
      return false
    } else {
      wx.cloud.callFunction({
        name: 'user',
        data: {
          action: 'getPhone',
          cloudID: e.detail.cloudID
        },
        success: function (res) {
          wx.cloud.callFunction({
            name: "user",
            data: {
              action: "edit",
              formdata: {
                phone_number: res.result.phoneNumber
              }
            }
          }).then(res => {
            that.xChildReload()
            // if(that.data.avatarUrl && that.data.value && that.data.avatarUrl!='https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/avatarUrl.png'){
              wx.showToast({
                title: '登录成功',
                icon:'none'
              })
              if(that.data.path!='/pages/navigation/using/index' && that.data.path){
                setTimeout(function(){
                  wx.redirectTo({
                    url: that.data.path+ that.data.parmas,
                  })
                },1500)
              }else{
                wx.switchTab({
                  url: '/pages/navigation/using/index',
                })
              }
          })
        }
      })
    }
  
  },
})